package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据用户id查询购物车列表
     * @param shoppingCart
     */
    List<ShoppingCart>list(ShoppingCart shoppingCart);

    /**
     * 更新购物车
     * @param  cartService
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void update(ShoppingCart cartService);

    /**
     * 插入购物车数据
     * @param shoppingCart
     * **/
    @Insert("insert into shopping_cart (name,user_id,image, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "VALUES (#{name},#{userId},#{image}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void insert(ShoppingCart shoppingCart);

    /**
     * 根据用户id删除购物车数据
     * @param currentId
     */
    @Delete("delete from shopping_cart where user_id = #{currentId}")
    void deleteByUserId(Long currentId);


    
    /**
     * 根据id查询购物车数据
     * @param dishId
     * @return
     */
    @Select("select * from shopping_cart where dish_id = #{dishId}")
    ShoppingCart getByDishId(Long dishId);
    /**
     *  根据id删除购物车数据
     * @param dishId
     */
    @Delete("delete from shopping_cart where dish_id = #{dishId}")
    void deleteById(Long dishId);
    /**
     * 更新商品数量
     * @param  shoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumberById(ShoppingCart shoppingCart);

    /**
     * 批量插入购物车数据
     * @param shoppingCartList
     */
    void insertBatch(List<ShoppingCart> shoppingCartList);
}
